﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GalaSoft.MvvmLight.Messaging;

namespace WebSiteAdminTool.UI.Services.Messaging
{
    public static class MessageManager
    {
        public static void SendMessage<T>(T message, object token = null) where T : MessageBase
        {
            Messenger.Default.Send(message, token);
        }
        
        public static void RegisterListener<T>(object recipient, Action<T> action) where T : MessageBase
        {
            Messenger.Default.Register(recipient, action);
        }

        public static void Notify(CommandsEnum command, object sender = null)
        {
            NotificationMessage<CommandsEnum> message = 
                new NotificationMessage<CommandsEnum>(sender, command, command.ToString());
            MessageManager.SendMessage<NotificationMessage<CommandsEnum>>(message);
        }

        public static void ListenForNotifications(object recipient, Action<NotificationMessage<CommandsEnum>> action)
        {
            Messenger.Default.Register<NotificationMessage<CommandsEnum>>(recipient, action);
        }
    }
}
